package com.myworkbench.workbench.application.impl;


import com.myworkbench.workbench.application.SecurityConfigApplication;
import com.myworkbench.workbench.domain.entity.resource.Resource;
import com.myworkbench.workbench.domain.entity.role.Role;
import com.myworkbench.workbench.domain.entity.user.User;
import com.myworkbench.workbench.domain.entity.user.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class SecurityConfigApplicationImpl  implements SecurityConfigApplication {

   private final  UserRepository userRepository;

   @Autowired
    public SecurityConfigApplicationImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public void saveUser(User user) {
        Assert.notNull(user," save user is null ");
        // 用户创建
        user.create();
    }

    @Override
    public void updateUser(User user) {
        Assert.notNull(user,"update user is null ");
        user.update();
    }

    @Override
    public void saveRole(Role role) {
        Assert.notNull(role,"save role is null ");
        role.create();
    }

    @Override
    public void updateRole(Role role) {
        Assert.notNull(role,"update role is null ");
        role.update();
    }

    @Override
    public void saveResource(Resource resource) {
        Assert.notNull(resource,"save resource is null ");
        resource.create();
    }

    @Override
    public void updateResource(Resource resource) {
        Assert.notNull(resource,"update resource is null ");
        resource.update();
    }

    @Override
    public void grantRole(User user, List<Role> roles) {
        // 用户授权
        Assert.notNull(user,"grant Role user is null ");
        // 批量删除


    }

    @Override
    public void grantResources(Role role, List<Resource> resources) {

    }
}
